/*
 * @Author: liuxiangnan 
 * @Date: 2018-12-13 00:48:36 
 * @Last Modified by: liuxiangnan
 * @Last Modified time: 2018-12-23 19:38:04
 */
// 本文件用于初始化网络请求，无需更改
import axios from "axios"
import {
  apis
} from "Utils/apis"
// 创建axios实例
const service = axios.create({
  baseURL: apis.baseURL, // api的base_url
  timeout: 60000, // 请求超时时间
  responseType: 'json',
  headers: {

  }
})
// request拦截器
service.interceptors.request.use(config => {
  return config
}, error => {
  return Promise.reject(error)
})

// respone拦截器
service.interceptors.response.use(
  response => {
    const result = response.data
    // 业务失败，需要跳转到404页面
    // if (!('access_token' in res)) {
    if ((result.state != '200' && result.state != 200) && (result.statusCode != '200' && result.statusCode != 200)) {
      $message.error(result.msg ? result.msg : result.message);
      return Promise.reject(result)
    }
    return response
  },
  error => {
    return Promise.reject(error)
  })
export default service
